{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Hm-0KA5mph28"
   },
   "source": [
    "# Story Book Author Agents\n",
    "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/cookbooks/notebooks/story_book_author_agents.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "ywRoojPlph2_"
   },
   "source": [
    "## Dependencies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "id": "2R0F425oph3A"
   },
   "outputs": [],
   "source": [
    "# Install dependencies without output\n",
    "!pip install requests > /dev/null\n",
    "!pip install praisonai > /dev/null\n",
    "!pip install openai > /dev/null\n",
    "!pip install praisonai[crewai] > /dev/null"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "ROBpAJbPph3B"
   },
   "source": [
    "## Tools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "id": "r9Jxxhopph3B"
   },
   "outputs": [],
   "source": [
    "#ToDo: Resolve File Read Issue\n",
    "import os\n",
    "import requests\n",
    "import re\n",
    "import subprocess\n",
    "from openai import OpenAI\n",
    "from crewai_tools import tool\n",
    "from praisonai_tools import FileReadTool\n",
    "\n",
    "\n",
    "# Tool to generate an image from a chapter's content and character details\n",
    "@tool\n",
    "def GenerateImageTool(chapter_content_and_character_details: str) -> str:\n",
    "    \"\"\"\n",
    "    Generates an image for a given chapter content, including character and location details.\n",
    "    Uses the OpenAI image generation API, saves it in the current folder, and returns the image path.\n",
    "\n",
    "    Args:\n",
    "        chapter_content_and_character_details (str): Description for the image generation.\n",
    "\n",
    "    Returns:\n",
    "        str: Path to the saved image.\n",
    "    \"\"\"\n",
    "    client = OpenAI(api_key=os.getenv(\"OPENAI_API_KEY\"))\n",
    "\n",
    "    response = client.images.generate(\n",
    "        model=\"dall-e-3\",\n",
    "        prompt=f\"Image is about: {chapter_content_and_character_details}. Style: Illustration. Create an illustration incorporating a vivid palette with an emphasis on shades of azure and emerald, augmented by splashes of gold for contrast and visual interest. The style should evoke the intricate detail and whimsy of early 20th-century storybook illustrations, blending realism with fantastical elements to create a sense of wonder and enchantment. The composition should be rich in texture, with a soft, luminous lighting that enhances the magical atmosphere. Attention to the interplay of light and shadow will add depth and dimensionality, inviting the viewer to delve into the scene. DON'T include ANY text in this image. DON'T include colour palettes in this image.\",\n",
    "        size=\"1024x1024\",\n",
    "        quality=\"standard\",\n",
    "        n=1,\n",
    "    )\n",
    "\n",
    "    # Get image URL and save it locally\n",
    "    image_url = response.data[0].url\n",
    "    words = chapter_content_and_character_details.split()[:5]\n",
    "    safe_words = [re.sub(r'[^a-zA-Z0-9_]', '', word) for word in words]\n",
    "    filename = \"_\".join(safe_words).lower() + \".png\"\n",
    "    filepath = os.path.join(os.getcwd(), filename)\n",
    "\n",
    "    # Download the image from the generated URL\n",
    "    image_response = requests.get(image_url)\n",
    "    if image_response.status_code == 200:\n",
    "        with open(filepath, 'wb') as file:\n",
    "            file.write(image_response.content)\n",
    "    else:\n",
    "        print(\"Failed to download the image.\")\n",
    "        return \"\"\n",
    "\n",
    "    return filepath\n",
    "\n",
    "@tool\n",
    "def MarkdownToPDFTool(markdownfile_name: str) -> str:\n",
    "    \"\"\"\n",
    "    Converts a Markdown file to a PDF document using the mdpdf command line application.\n",
    "\n",
    "    Args:\n",
    "        markdownfile_name (str): Path to the input Markdown file.\n",
    "\n",
    "    Returns:\n",
    "        str: Path to the generated PDF file.\n",
    "    \"\"\"\n",
    "    output_file = os.path.splitext(markdownfile_name)[0] + '.pdf'\n",
    "\n",
    "    # Command to convert markdown to PDF using mdpdf\n",
    "    cmd = ['mdpdf', '--output', output_file, markdownfile_name]\n",
    "\n",
    "    # Execute the command and handle errors if any\n",
    "    try:\n",
    "        subprocess.run(cmd, check=True)\n",
    "    except subprocess.CalledProcessError as e:\n",
    "        print(f\"Error during PDF conversion: {e}\")\n",
    "        return \"\"\n",
    "\n",
    "    return output_file"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Cz1ImM0Uph3C"
   },
   "source": [
    "## YAML Prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "TO8UiZ7wph3C"
   },
   "outputs": [],
   "source": [
    "agent_yaml = \"\"\"\n",
    "framework: crewai\n",
    "topic: \"Children's Storybook Creation\"\n",
    "roles:\n",
    "  story_outliner:\n",
    "    role: \"Story Outliner\"\n",
    "    backstory: \"An imaginative creator who lays the foundation of captivating stories for children.\"\n",
    "    goal: \"Develop an outline for a children's storybook about Animals, including chapter titles and characters for 5 chapters.\"\n",
    "    tasks:\n",
    "      outline_development:\n",
    "        description: \"Create an outline for the children's storybook about Animals, detailing chapter titles and character descriptions for 5 chapters.\"\n",
    "        expected_output: \"A structured outline document containing 5 chapter titles, with detailed character descriptions and the main plot points for each chapter.\"\n",
    "  story_writer:\n",
    "    role: \"Story Writer\"\n",
    "    backstory: \"A talented storyteller who brings to life the world and characters outlined, crafting engaging and imaginative tales for children.\"\n",
    "    goal: \"Write the full content of the story for all 5 chapters, each chapter 100 words, weaving together the narratives and characters outlined.\"\n",
    "    tasks:\n",
    "      story_content_creation:\n",
    "        description: \"Using the outline provided, write the full story content for all chapters, ensuring a cohesive and engaging narrative for children. Each chapter should have 100 words.\"\n",
    "        expected_output: \"A complete manuscript of the children's storybook about Animals with 5 chapters, each containing approximately 100 words, following the provided outline.\"\n",
    "  image_generator:\n",
    "    role: \"Image Generator\"\n",
    "    backstory: \"A creative AI specialized in visual storytelling, bringing each chapter to life through imaginative imagery.\"\n",
    "    goal: \"Generate one image per chapter content provided by the story outliner. Generate a total of 5 images sequentially.\"\n",
    "    tasks:\n",
    "      image_creation:\n",
    "        description: \"Generate 5 images that capture the essence of the children's storybook about Animals, aligning with the themes, characters, and narrative outlined for the chapters.\"\n",
    "        expected_output: \"A set of 5 digital image files that visually represent the story, incorporating elements from the characters and plot as described in the outline.\"\n",
    "    tools:\n",
    "      - GenerateImageTool\n",
    "  content_formatter:\n",
    "    role: \"Content Formatter\"\n",
    "    backstory: \"A meticulous formatter who enhances the readability and presentation of the storybook.\"\n",
    "    goal: \"Format the written story content in markdown, including images at the beginning of each chapter.\"\n",
    "    tasks:\n",
    "      content_formatting:\n",
    "        description: \"Format the story content in markdown, including an image at the beginning of each chapter.\"\n",
    "        expected_output: \"The entire storybook content formatted in markdown, with each chapter title followed by the corresponding image and the chapter content.\"\n",
    "    tools:\n",
    "      - FileReadTool\n",
    "  markdown_to_pdf_creator:\n",
    "    role: \"PDF Converter\"\n",
    "    backstory: \"An efficient converter that transforms Markdown files into professionally formatted PDF documents.\"\n",
    "    goal: \"Convert the Markdown file to a PDF document. Ensure the file story.md is converted.\"\n",
    "    tasks:\n",
    "      pdf_conversion:\n",
    "        description: \"Convert a Markdown file to a PDF document, ensuring the preservation of formatting, structure, and embedded images using the mdpdf library.\"\n",
    "        expected_output: \"A PDF file generated from the Markdown input, accurately reflecting the content with proper formatting.\"\n",
    "    tools:\n",
    "      - MarkdownToPDFTool\n",
    "dependencies: []\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "rRXiw2CVph3D"
   },
   "source": [
    "## Main"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "HQ_0lMYhph3D",
    "outputId": "7f026fbd-9efd-49d3-ae7c-b01e68d6ccf4"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[1m\u001b[95m [2024-11-02 16:26:50][DEBUG]: == Working Agent: Story Outliner\u001b[00m\n",
      "\u001b[1m\u001b[95m [2024-11-02 16:26:50][INFO]: == Starting Task: Create an outline for the children's storybook about Animals, detailing chapter titles and character descriptions for 5 chapters.\u001b[00m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n",
      "\u001b[32;1m\u001b[1;3mI now can give a great answer  \n",
      "Final Answer: \n",
      "\n",
      "**Outline for Children's Storybook: \"The Great Animal Adventure\"**\n",
      "\n",
      "**Chapter 1: The Secret of the Enchanted Forest**  \n",
      "*Character Descriptions:*  \n",
      "- **Leo the Lion**: A brave and curious lion with a golden mane and a heart of gold. He loves exploring new places and is known for his leadership qualities.  \n",
      "- **Tilly the Tortoise**: A wise and slow-moving tortoise who knows all the secrets of the forest. She is patient and offers sage advice to her friends.  \n",
      "- **Benny the Bunny**: A playful and energetic bunny who enjoys hopping around and making friends. He is always up for an adventure and has a great sense of humor.\n",
      "\n",
      "*Main Plot Points:*  \n",
      "- Leo, Tilly, and Benny gather at the edge of the Enchanted Forest, where they hear tales of hidden treasures.  \n",
      "- They decide to embark on an adventure to find the treasure that is said to be guarded by a mysterious creature.  \n",
      "- As they enter the forest, they encounter magical plants and curious animals, setting the tone for their exciting journey.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 2: The Mysterious Guardian**  \n",
      "*Character Descriptions:*  \n",
      "- **Gizmo the Owl**: A wise old owl with big glasses and a penchant for riddles. He serves as the guardian of the forest and knows the secrets of the treasure.  \n",
      "- **Flora the Fox**: A clever and cunning fox who loves to play tricks but has a good heart. She becomes both a friend and a challenge for the group.\n",
      "\n",
      "*Main Plot Points:*  \n",
      "- The trio meets Gizmo, who tells them they must solve his riddle to proceed.  \n",
      "- Tilly’s wisdom helps them decipher the riddle, and they earn Gizmo's respect.  \n",
      "- Flora the Fox appears and offers to guide them, but only if they can beat her in a game of wits.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 3: The Game of Wits**  \n",
      "*Character Descriptions:*  \n",
      "- **Chester the Chipmunk**: A cheeky little chipmunk who loves nuts and is always ready to help friends in tricky situations.  \n",
      "- **Bella the Bird**: A cheerful bird who has a beautiful singing voice and can fly high above to scout for dangers.\n",
      "\n",
      "*Main Plot Points:*  \n",
      "- The game involves various challenges, including puzzles and races, testing each character's unique abilities.  \n",
      "- Benny uses his speed to win a race, while Tilly relies on her cleverness to solve a tricky puzzle.  \n",
      "- Flora realizes the strength of teamwork and decides to join them after they defeat her in the final challenge.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 4: The Hidden Treasure**  \n",
      "*Character Descriptions:*  \n",
      "- **The Mischievous Monkeys**: A group of playful monkeys who love to swing from tree to tree and steal shiny objects. They add humor and mischief to the adventure.  \n",
      "- **Maya the Mouse**: A tiny but brave mouse who dreams of big adventures and has a knack for finding hidden paths.\n",
      "\n",
      "*Main Plot Points:*  \n",
      "- The group finally locates the treasure, only to find it protected by the Mischievous Monkeys.  \n",
      "- The monkeys challenge them to retrieve the treasure by performing goofy tasks, leading to laughter and camaraderie.  \n",
      "- Maya helps the group by sneaking past the monkeys, showcasing that even small friends can make a big difference.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 5: A Treasure of Friendship**  \n",
      "*Character Descriptions:*  \n",
      "- **Sunny the Squirrel**: A cheerful and optimistic squirrel who loves to share food and laughter with others.  \n",
      "- **All the Forest Animals**: Various animals join the celebration, each bringing their unique traits and talents to the party.\n",
      "\n",
      "*Main Plot Points:*  \n",
      "- The treasure turns out to be a magical fruit that grants wishes but teaches that friendship is the real treasure.  \n",
      "- The group celebrates their adventure with a feast, inviting all the animals of the forest.  \n",
      "- They learn valuable lessons about teamwork, kindness, and the importance of friendship, promising to explore more together in the future.\n",
      "\n",
      "---\n",
      "\n",
      "This structured outline captures the essence of an engaging story for children, emphasizing friendship, adventure, and teamwork while featuring relatable and diverse animal characters.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\u001b[1m\u001b[92m [2024-11-02 16:27:04][DEBUG]: == [Story Outliner] Task output: **Outline for Children's Storybook: \"The Great Animal Adventure\"**\n",
      "\n",
      "**Chapter 1: The Secret of the Enchanted Forest**  \n",
      "*Character Descriptions:*  \n",
      "- **Leo the Lion**: A brave and curious lion with a golden mane and a heart of gold. He loves exploring new places and is known for his leadership qualities.  \n",
      "- **Tilly the Tortoise**: A wise and slow-moving tortoise who knows all the secrets of the forest. She is patient and offers sage advice to her friends.  \n",
      "- **Benny the Bunny**: A playful and energetic bunny who enjoys hopping around and making friends. He is always up for an adventure and has a great sense of humor.\n",
      "\n",
      "*Main Plot Points:*  \n",
      "- Leo, Tilly, and Benny gather at the edge of the Enchanted Forest, where they hear tales of hidden treasures.  \n",
      "- They decide to embark on an adventure to find the treasure that is said to be guarded by a mysterious creature.  \n",
      "- As they enter the forest, they encounter magical plants and curious animals, setting the tone for their exciting journey.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 2: The Mysterious Guardian**  \n",
      "*Character Descriptions:*  \n",
      "- **Gizmo the Owl**: A wise old owl with big glasses and a penchant for riddles. He serves as the guardian of the forest and knows the secrets of the treasure.  \n",
      "- **Flora the Fox**: A clever and cunning fox who loves to play tricks but has a good heart. She becomes both a friend and a challenge for the group.\n",
      "\n",
      "*Main Plot Points:*  \n",
      "- The trio meets Gizmo, who tells them they must solve his riddle to proceed.  \n",
      "- Tilly’s wisdom helps them decipher the riddle, and they earn Gizmo's respect.  \n",
      "- Flora the Fox appears and offers to guide them, but only if they can beat her in a game of wits.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 3: The Game of Wits**  \n",
      "*Character Descriptions:*  \n",
      "- **Chester the Chipmunk**: A cheeky little chipmunk who loves nuts and is always ready to help friends in tricky situations.  \n",
      "- **Bella the Bird**: A cheerful bird who has a beautiful singing voice and can fly high above to scout for dangers.\n",
      "\n",
      "*Main Plot Points:*  \n",
      "- The game involves various challenges, including puzzles and races, testing each character's unique abilities.  \n",
      "- Benny uses his speed to win a race, while Tilly relies on her cleverness to solve a tricky puzzle.  \n",
      "- Flora realizes the strength of teamwork and decides to join them after they defeat her in the final challenge.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 4: The Hidden Treasure**  \n",
      "*Character Descriptions:*  \n",
      "- **The Mischievous Monkeys**: A group of playful monkeys who love to swing from tree to tree and steal shiny objects. They add humor and mischief to the adventure.  \n",
      "- **Maya the Mouse**: A tiny but brave mouse who dreams of big adventures and has a knack for finding hidden paths.\n",
      "\n",
      "*Main Plot Points:*  \n",
      "- The group finally locates the treasure, only to find it protected by the Mischievous Monkeys.  \n",
      "- The monkeys challenge them to retrieve the treasure by performing goofy tasks, leading to laughter and camaraderie.  \n",
      "- Maya helps the group by sneaking past the monkeys, showcasing that even small friends can make a big difference.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 5: A Treasure of Friendship**  \n",
      "*Character Descriptions:*  \n",
      "- **Sunny the Squirrel**: A cheerful and optimistic squirrel who loves to share food and laughter with others.  \n",
      "- **All the Forest Animals**: Various animals join the celebration, each bringing their unique traits and talents to the party.\n",
      "\n",
      "*Main Plot Points:*  \n",
      "- The treasure turns out to be a magical fruit that grants wishes but teaches that friendship is the real treasure.  \n",
      "- The group celebrates their adventure with a feast, inviting all the animals of the forest.  \n",
      "- They learn valuable lessons about teamwork, kindness, and the importance of friendship, promising to explore more together in the future.\n",
      "\n",
      "---\n",
      "\n",
      "This structured outline captures the essence of an engaging story for children, emphasizing friendship, adventure, and teamwork while featuring relatable and diverse animal characters.\n",
      "\n",
      "\u001b[00m\n",
      "\u001b[1m\u001b[95m [2024-11-02 16:27:04][DEBUG]: == Working Agent: Story Writer\u001b[00m\n",
      "\u001b[1m\u001b[95m [2024-11-02 16:27:04][INFO]: == Starting Task: Using the outline provided, write the full story content for all chapters, ensuring a cohesive and engaging narrative for children. Each chapter should have 100 words.\u001b[00m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n",
      "\u001b[32;1m\u001b[1;3mI now can give a great answer  \n",
      "Final Answer: \n",
      "\n",
      "**Chapter 1: The Secret of the Enchanted Forest**  \n",
      "At the edge of the Enchanted Forest, Leo the Lion, Tilly the Tortoise, and Benny the Bunny gathered, their hearts filled with excitement. Tales of hidden treasures whispered through the trees, and they decided to embark on an adventure. \"What if we find it?\" Benny exclaimed, hopping with joy. Tilly, wise and patient, smiled, \"Let’s explore and see!\" As they stepped into the forest, vibrant magical plants danced in the breeze, and curious creatures peeked from behind the trees. With every step, their adventure grew brighter, and the promise of treasure sparkled in their eyes.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 2: The Mysterious Guardian**  \n",
      "Deep in the forest, they encountered Gizmo the Owl, perched on a gnarled branch, his big glasses perched on his beak. \"To find the treasure, you must solve my riddle,\" he hooted. Tilly pondered, her mind whirring, and soon the answer came to her. The friends cheered as Gizmo nodded in approval. Just then, Flora the Fox, sly and clever, appeared and offered her help. \"Only if you can outsmart me in a game of wits,\" she challenged. The group exchanged determined glances, ready to face whatever clever tricks Flora had up her sleeve.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 3: The Game of Wits**  \n",
      "The game began with puzzles and races, each challenge testing their unique talents. Benny dashed ahead in a race, his little legs pumping with speed, while Tilly carefully pieced together a tricky puzzle. Chester the Chipmunk cheered them on, providing nutty encouragement. Finally, Flora challenged them to a final test of teamwork. Working together, Leo roared for confidence, Tilly shared her wisdom, and Benny hopped with glee. They succeeded, impressing Flora, who realized that friendship made them stronger. With a smile, she joined their adventure, excited to explore the forest together.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 4: The Hidden Treasure**  \n",
      "As they ventured deeper into the forest, the group found the hidden treasure, but it was guarded by the Mischievous Monkeys! Swinging from branches, the monkeys chattered, challenging them to silly tasks. \"Can you tickle your toes while hopping on one leg?\" they giggled. Laughter filled the air as the friends performed the goofy tasks, their spirits high. Maya the Mouse, small but brave, snuck past the monkeys, cleverly avoiding their gaze. With teamwork and humor, they outsmarted the mischievous guardians and claimed the treasure, a beautiful chest sparkling with promise.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 5: A Treasure of Friendship**  \n",
      "When they finally opened the treasure chest, they found magical fruits that glowed with colors of the rainbow. \"These can grant wishes!\" Benny exclaimed. But as they shared the fruits, they learned that the greatest treasure was their friendship. They decided to host a feast, inviting all the forest animals to celebrate. Sunny the Squirrel brought nuts, and Bella the Bird sang sweet melodies. Together, they laughed, danced, and feasted, creating memories for a lifetime. The friends promised to explore more adventures together, knowing that with friendship, anything was possible.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\u001b[1m\u001b[92m [2024-11-02 16:27:12][DEBUG]: == [Story Writer] Task output: **Chapter 1: The Secret of the Enchanted Forest**  \n",
      "At the edge of the Enchanted Forest, Leo the Lion, Tilly the Tortoise, and Benny the Bunny gathered, their hearts filled with excitement. Tales of hidden treasures whispered through the trees, and they decided to embark on an adventure. \"What if we find it?\" Benny exclaimed, hopping with joy. Tilly, wise and patient, smiled, \"Let’s explore and see!\" As they stepped into the forest, vibrant magical plants danced in the breeze, and curious creatures peeked from behind the trees. With every step, their adventure grew brighter, and the promise of treasure sparkled in their eyes.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 2: The Mysterious Guardian**  \n",
      "Deep in the forest, they encountered Gizmo the Owl, perched on a gnarled branch, his big glasses perched on his beak. \"To find the treasure, you must solve my riddle,\" he hooted. Tilly pondered, her mind whirring, and soon the answer came to her. The friends cheered as Gizmo nodded in approval. Just then, Flora the Fox, sly and clever, appeared and offered her help. \"Only if you can outsmart me in a game of wits,\" she challenged. The group exchanged determined glances, ready to face whatever clever tricks Flora had up her sleeve.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 3: The Game of Wits**  \n",
      "The game began with puzzles and races, each challenge testing their unique talents. Benny dashed ahead in a race, his little legs pumping with speed, while Tilly carefully pieced together a tricky puzzle. Chester the Chipmunk cheered them on, providing nutty encouragement. Finally, Flora challenged them to a final test of teamwork. Working together, Leo roared for confidence, Tilly shared her wisdom, and Benny hopped with glee. They succeeded, impressing Flora, who realized that friendship made them stronger. With a smile, she joined their adventure, excited to explore the forest together.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 4: The Hidden Treasure**  \n",
      "As they ventured deeper into the forest, the group found the hidden treasure, but it was guarded by the Mischievous Monkeys! Swinging from branches, the monkeys chattered, challenging them to silly tasks. \"Can you tickle your toes while hopping on one leg?\" they giggled. Laughter filled the air as the friends performed the goofy tasks, their spirits high. Maya the Mouse, small but brave, snuck past the monkeys, cleverly avoiding their gaze. With teamwork and humor, they outsmarted the mischievous guardians and claimed the treasure, a beautiful chest sparkling with promise.\n",
      "\n",
      "---\n",
      "\n",
      "**Chapter 5: A Treasure of Friendship**  \n",
      "When they finally opened the treasure chest, they found magical fruits that glowed with colors of the rainbow. \"These can grant wishes!\" Benny exclaimed. But as they shared the fruits, they learned that the greatest treasure was their friendship. They decided to host a feast, inviting all the forest animals to celebrate. Sunny the Squirrel brought nuts, and Bella the Bird sang sweet melodies. Together, they laughed, danced, and feasted, creating memories for a lifetime. The friends promised to explore more adventures together, knowing that with friendship, anything was possible.\n",
      "\n",
      "\u001b[00m\n",
      "\u001b[1m\u001b[95m [2024-11-02 16:27:12][DEBUG]: == Working Agent: Image Generator\u001b[00m\n",
      "\u001b[1m\u001b[95m [2024-11-02 16:27:12][INFO]: == Starting Task: Generate 5 images that capture the essence of the children's storybook about Animals, aligning with the themes, characters, and narrative outlined for the chapters.\u001b[00m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n",
      "\u001b[32;1m\u001b[1;3mI now can give a great answer  \n",
      "Final Answer: \n",
      "\n",
      "1. **Image 1: The Secret of the Enchanted Forest**  \n",
      "   A vibrant scene depicting Leo the Lion, Tilly the Tortoise, and Benny the Bunny at the edge of the Enchanted Forest. The forest is lush and alive with colorful magical plants and curious creatures peeking from behind the trees. Leo stands confidently, Tilly smiles wisely, and Benny hops with excitement, their expressions filled with anticipation for the adventure ahead.\n",
      "\n",
      "2. **Image 2: The Mysterious Guardian**  \n",
      "   Deep within the forest, Gizmo the Owl perches on a gnarled branch, wearing oversized glasses. The background is filled with enchanting foliage. Tilly stands below, deep in thought, while Leo and Benny watch with eager expressions. Flora the Fox appears to the side, sly and clever, ready to challenge them. The atmosphere is filled with mystery and the promise of riddles to solve.\n",
      "\n",
      "3. **Image 3: The Game of Wits**  \n",
      "   An action-packed scene where Benny races ahead, with Tilly carefully piecing together a puzzle while Chester the Chipmunk cheers them on from a nearby branch. The backdrop shows a whimsical forest filled with colorful flowers and trees. Flora watches with a playful smirk, setting the stage for a friendly competition. The friends are engaged in their unique talents, showcasing teamwork and determination.\n",
      "\n",
      "4. **Image 4: The Hidden Treasure**  \n",
      "   The group stands before a sparkling treasure chest surrounded by mischievous monkeys swinging from the trees. The monkeys are playfully challenging the friends with silly tasks, while Maya the Mouse sneaks stealthily in the background. The atmosphere is lively, filled with laughter and excitement as the characters prepare to outsmart the monkeys and claim their treasure.\n",
      "\n",
      "5. **Image 5: A Treasure of Friendship**  \n",
      "   A joyous feast scene under the canopy of the forest, filled with colorful magical fruits glowing in the center. Benny excitedly shares the fruits with Leo, Tilly, and their new friends from the forest, including Sunny the Squirrel and Bella the Bird, who sing sweet melodies. The friends are laughing, dancing, and celebrating together, creating a warm, inviting atmosphere that captures the essence of friendship and shared adventures.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\u001b[1m\u001b[92m [2024-11-02 16:27:18][DEBUG]: == [Image Generator] Task output: 1. **Image 1: The Secret of the Enchanted Forest**  \n",
      "   A vibrant scene depicting Leo the Lion, Tilly the Tortoise, and Benny the Bunny at the edge of the Enchanted Forest. The forest is lush and alive with colorful magical plants and curious creatures peeking from behind the trees. Leo stands confidently, Tilly smiles wisely, and Benny hops with excitement, their expressions filled with anticipation for the adventure ahead.\n",
      "\n",
      "2. **Image 2: The Mysterious Guardian**  \n",
      "   Deep within the forest, Gizmo the Owl perches on a gnarled branch, wearing oversized glasses. The background is filled with enchanting foliage. Tilly stands below, deep in thought, while Leo and Benny watch with eager expressions. Flora the Fox appears to the side, sly and clever, ready to challenge them. The atmosphere is filled with mystery and the promise of riddles to solve.\n",
      "\n",
      "3. **Image 3: The Game of Wits**  \n",
      "   An action-packed scene where Benny races ahead, with Tilly carefully piecing together a puzzle while Chester the Chipmunk cheers them on from a nearby branch. The backdrop shows a whimsical forest filled with colorful flowers and trees. Flora watches with a playful smirk, setting the stage for a friendly competition. The friends are engaged in their unique talents, showcasing teamwork and determination.\n",
      "\n",
      "4. **Image 4: The Hidden Treasure**  \n",
      "   The group stands before a sparkling treasure chest surrounded by mischievous monkeys swinging from the trees. The monkeys are playfully challenging the friends with silly tasks, while Maya the Mouse sneaks stealthily in the background. The atmosphere is lively, filled with laughter and excitement as the characters prepare to outsmart the monkeys and claim their treasure.\n",
      "\n",
      "5. **Image 5: A Treasure of Friendship**  \n",
      "   A joyous feast scene under the canopy of the forest, filled with colorful magical fruits glowing in the center. Benny excitedly shares the fruits with Leo, Tilly, and their new friends from the forest, including Sunny the Squirrel and Bella the Bird, who sing sweet melodies. The friends are laughing, dancing, and celebrating together, creating a warm, inviting atmosphere that captures the essence of friendship and shared adventures.\n",
      "\n",
      "\u001b[00m\n",
      "\u001b[1m\u001b[95m [2024-11-02 16:27:18][DEBUG]: == Working Agent: Content Formatter\u001b[00m\n",
      "\u001b[1m\u001b[95m [2024-11-02 16:27:18][INFO]: == Starting Task: Format the story content in markdown, including an image at the beginning of each chapter.\u001b[00m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n",
      "\u001b[32;1m\u001b[1;3mAction: Read a file's content  \n",
      "Action Input: {\"file_path\": \"story_content.txt\"}  \u001b[0m"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.10/dist-packages/pydantic/main.py:214: UserWarning: A custom validator is returning a value other than `self`.\n",
      "Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\n",
      "See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[95m \n",
      "\n",
      "Fail to read the file story_content.txt. Error: [Errno 2] No such file or directory: 'story_content.txt'\n",
      "\u001b[00m\n"
     ]
    },
    {
     "ename": "APIError",
     "evalue": "The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAPIError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-5-6ab2c8330d8d>\u001b[0m in \u001b[0;36m<cell line: 13>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     11\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     12\u001b[0m \u001b[0;31m# Run PraisonAI\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 13\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpraisonai\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     14\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     15\u001b[0m \u001b[0;31m# Print the result\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/praisonai/cli.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    110\u001b[0m         \u001b[0mRun\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mPraisonAI\u001b[0m \u001b[0mapplication\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    111\u001b[0m         \"\"\"\n\u001b[0;32m--> 112\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    113\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    114\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mmain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/praisonai/cli.py\u001b[0m in \u001b[0;36mmain\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    256\u001b[0m                 \u001b[0mtools\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtools\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    257\u001b[0m             )\n\u001b[0;32m--> 258\u001b[0;31m             \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0magents_generator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgenerate_crew_and_kickoff\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    259\u001b[0m             \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    260\u001b[0m             \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/praisonai/agents_generator.py\u001b[0m in \u001b[0;36mgenerate_crew_and_kickoff\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    274\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mAGENTOPS_AVAILABLE\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    275\u001b[0m                 \u001b[0magentops\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0menviron\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"AGENTOPS_API_KEY\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtags\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"crewai\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 276\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_run_crewai\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtopic\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtools_dict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    277\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    278\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m_run_autogen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mconfig\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtopic\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtools_dict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/praisonai/agents_generator.py\u001b[0m in \u001b[0;36m_run_crewai\u001b[0;34m(self, config, topic, tools_dict)\u001b[0m\n\u001b[1;32m    465\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlogger\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdebug\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"Tasks: {crew.tasks}\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    466\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 467\u001b[0;31m         \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcrew\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkickoff\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    468\u001b[0m         \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34mf\"### Task Output ###\\n{response}\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    469\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/crewai/crew.py\u001b[0m in \u001b[0;36mkickoff\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m    312\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    313\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mProcess\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msequential\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 314\u001b[0;31m             \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_run_sequential_process\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    315\u001b[0m         \u001b[0;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mProcess\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhierarchical\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    316\u001b[0m             \u001b[0;31m# type: ignore # Unpacking a string is disallowed\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/crewai/crew.py\u001b[0m in \u001b[0;36m_run_sequential_process\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    394\u001b[0m                     \u001b[0magent\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrole\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtask\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtask\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdescription\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstatus\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"started\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    395\u001b[0m                 )\n\u001b[0;32m--> 396\u001b[0;31m             \u001b[0moutput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtask\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcontext\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtask_output\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    397\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    398\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mtask\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masync_execution\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/crewai/task.py\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(self, agent, context, tools)\u001b[0m\n\u001b[1;32m    209\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_thread\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstart\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    210\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 211\u001b[0;31m             result = self._execute(\n\u001b[0m\u001b[1;32m    212\u001b[0m                 \u001b[0mtask\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    213\u001b[0m                 \u001b[0magent\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0magent\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/crewai/task.py\u001b[0m in \u001b[0;36m_execute\u001b[0;34m(self, agent, task, context, tools)\u001b[0m\n\u001b[1;32m    218\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    219\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m_execute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0magent\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtask\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtools\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 220\u001b[0;31m         result = agent.execute_task(\n\u001b[0m\u001b[1;32m    221\u001b[0m             \u001b[0mtask\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtask\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    222\u001b[0m             \u001b[0mcontext\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcontext\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/crewai/agent.py\u001b[0m in \u001b[0;36mexecute_task\u001b[0;34m(self, task, context, tools)\u001b[0m\n\u001b[1;32m    160\u001b[0m             \u001b[0mtask_prompt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_use_trained_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtask_prompt\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtask_prompt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    161\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 162\u001b[0;31m         result = self.agent_executor.invoke(\n\u001b[0m\u001b[1;32m    163\u001b[0m             {\n\u001b[1;32m    164\u001b[0m                 \u001b[0;34m\"input\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtask_prompt\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain/chains/base.py\u001b[0m in \u001b[0;36minvoke\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m    161\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mBaseException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    162\u001b[0m             \u001b[0mrun_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_chain_error\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 163\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    164\u001b[0m         \u001b[0mrun_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_chain_end\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    165\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain/chains/base.py\u001b[0m in \u001b[0;36minvoke\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m    151\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_validate_inputs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    152\u001b[0m             outputs = (\n\u001b[0;32m--> 153\u001b[0;31m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrun_manager\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrun_manager\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    154\u001b[0m                 \u001b[0;32mif\u001b[0m \u001b[0mnew_arg_supported\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    155\u001b[0m                 \u001b[0;32melse\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/crewai/agents/executor.py\u001b[0m in \u001b[0;36m_call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m     69\u001b[0m         \u001b[0;32mwhile\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_should_continue\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miterations\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtime_elapsed\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     70\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrequest_within_rpm_limit\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrequest_within_rpm_limit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 71\u001b[0;31m                 next_step_output = self._take_next_step(\n\u001b[0m\u001b[1;32m     72\u001b[0m                     \u001b[0mname_to_tool_map\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     73\u001b[0m                     \u001b[0mcolor_mapping\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain/agents/agent.py\u001b[0m in \u001b[0;36m_take_next_step\u001b[0;34m(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)\u001b[0m\n\u001b[1;32m   1136\u001b[0m     ) -> Union[AgentFinish, List[Tuple[AgentAction, str]]]:\n\u001b[1;32m   1137\u001b[0m         return self._consume_next_step(\n\u001b[0;32m-> 1138\u001b[0;31m             [\n\u001b[0m\u001b[1;32m   1139\u001b[0m                 \u001b[0ma\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1140\u001b[0m                 for a in self._iter_next_step(\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain/agents/agent.py\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m   1136\u001b[0m     ) -> Union[AgentFinish, List[Tuple[AgentAction, str]]]:\n\u001b[1;32m   1137\u001b[0m         return self._consume_next_step(\n\u001b[0;32m-> 1138\u001b[0;31m             [\n\u001b[0m\u001b[1;32m   1139\u001b[0m                 \u001b[0ma\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1140\u001b[0m                 for a in self._iter_next_step(\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/crewai/agents/executor.py\u001b[0m in \u001b[0;36m_iter_next_step\u001b[0;34m(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)\u001b[0m\n\u001b[1;32m    133\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    134\u001b[0m             \u001b[0;31m# Call the LLM to see what to do.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 135\u001b[0;31m             output = self.agent.plan(  # type: ignore #  Incompatible types in assignment (expression has type \"AgentAction | AgentFinish | list[AgentAction]\", variable has type \"AgentAction\")\n\u001b[0m\u001b[1;32m    136\u001b[0m                 \u001b[0mintermediate_steps\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    137\u001b[0m                 \u001b[0mcallbacks\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrun_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_child\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mrun_manager\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain/agents/agent.py\u001b[0m in \u001b[0;36mplan\u001b[0;34m(self, intermediate_steps, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    395\u001b[0m             \u001b[0;31m# Because the response from the plan is not a generator, we need to\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    396\u001b[0m             \u001b[0;31m# accumulate the output into final output and return that.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 397\u001b[0;31m             \u001b[0;32mfor\u001b[0m \u001b[0mchunk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrunnable\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstream\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mconfig\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0;34m\"callbacks\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mcallbacks\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    398\u001b[0m                 \u001b[0;32mif\u001b[0m \u001b[0mfinal_output\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    399\u001b[0m                     \u001b[0mfinal_output\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mchunk\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain_core/runnables/base.py\u001b[0m in \u001b[0;36mstream\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m   2873\u001b[0m         \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mAny\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2874\u001b[0m     ) -> Iterator[Output]:\n\u001b[0;32m-> 2875\u001b[0;31m         \u001b[0;32myield\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtransform\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mconfig\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   2876\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2877\u001b[0m     async def atransform(\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain_core/runnables/base.py\u001b[0m in \u001b[0;36mtransform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m   2860\u001b[0m         \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mAny\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2861\u001b[0m     ) -> Iterator[Output]:\n\u001b[0;32m-> 2862\u001b[0;31m         yield from self._transform_stream_with_config(\n\u001b[0m\u001b[1;32m   2863\u001b[0m             \u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2864\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_transform\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain_core/runnables/base.py\u001b[0m in \u001b[0;36m_transform_stream_with_config\u001b[0;34m(self, input, transformer, config, run_type, **kwargs)\u001b[0m\n\u001b[1;32m   1879\u001b[0m             \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1880\u001b[0m                 \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1881\u001b[0;31m                     \u001b[0mchunk\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mOutput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnext\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0miterator\u001b[0m\u001b[0;34m)\u001b[0m  \u001b[0;31m# type: ignore\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1882\u001b[0m                     \u001b[0;32myield\u001b[0m \u001b[0mchunk\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1883\u001b[0m                     \u001b[0;32mif\u001b[0m \u001b[0mfinal_output_supported\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain_core/runnables/base.py\u001b[0m in \u001b[0;36m_transform\u001b[0;34m(self, input, run_manager, config)\u001b[0m\n\u001b[1;32m   2824\u001b[0m             )\n\u001b[1;32m   2825\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2826\u001b[0;31m         \u001b[0;32mfor\u001b[0m \u001b[0moutput\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mfinal_pipeline\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   2827\u001b[0m             \u001b[0;32myield\u001b[0m \u001b[0moutput\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2828\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain_core/runnables/base.py\u001b[0m in \u001b[0;36mtransform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m   1280\u001b[0m         \u001b[0mgot_first_val\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1281\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1282\u001b[0;31m         \u001b[0;32mfor\u001b[0m \u001b[0michunk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1283\u001b[0m             \u001b[0;31m# The default implementation of transform is to buffer input and\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1284\u001b[0m             \u001b[0;31m# then call stream.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain_core/runnables/base.py\u001b[0m in \u001b[0;36mtransform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m   4734\u001b[0m         \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mAny\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4735\u001b[0m     ) -> Iterator[Output]:\n\u001b[0;32m-> 4736\u001b[0;31m         yield from self.bound.transform(\n\u001b[0m\u001b[1;32m   4737\u001b[0m             \u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4738\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_merge_configs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain_core/runnables/base.py\u001b[0m in \u001b[0;36mtransform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m   1298\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1299\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mgot_first_val\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1300\u001b[0;31m             \u001b[0;32myield\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstream\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfinal\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mconfig\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1301\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1302\u001b[0m     async def atransform(\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain_core/language_models/chat_models.py\u001b[0m in \u001b[0;36mstream\u001b[0;34m(self, input, config, stop, **kwargs)\u001b[0m\n\u001b[1;32m    247\u001b[0m                     ),\n\u001b[1;32m    248\u001b[0m                 )\n\u001b[0;32m--> 249\u001b[0;31m                 \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    250\u001b[0m             \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    251\u001b[0m                 \u001b[0mrun_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_llm_end\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mLLMResult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgenerations\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mgeneration\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain_core/language_models/chat_models.py\u001b[0m in \u001b[0;36mstream\u001b[0;34m(self, input, config, stop, **kwargs)\u001b[0m\n\u001b[1;32m    227\u001b[0m             \u001b[0mgeneration\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mChatGenerationChunk\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    228\u001b[0m             \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 229\u001b[0;31m                 \u001b[0;32mfor\u001b[0m \u001b[0mchunk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_stream\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessages\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstop\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    230\u001b[0m                     \u001b[0;32mif\u001b[0m \u001b[0mchunk\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mid\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    231\u001b[0m                         \u001b[0mchunk\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mid\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34mf\"run-{run_manager.run_id}\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/langchain_openai/chat_models/base.py\u001b[0m in \u001b[0;36m_stream\u001b[0;34m(self, messages, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m    479\u001b[0m         \u001b[0mdefault_chunk_class\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mAIMessageChunk\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    480\u001b[0m         \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessages\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmessage_dicts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 481\u001b[0;31m             \u001b[0;32mfor\u001b[0m \u001b[0mchunk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    482\u001b[0m                 \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mchunk\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    483\u001b[0m                     \u001b[0mchunk\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mchunk\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodel_dump\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/openai/_streaming.py\u001b[0m in \u001b[0;36m__iter__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m     44\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     45\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m__iter__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mIterator\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0m_T\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 46\u001b[0;31m         \u001b[0;32mfor\u001b[0m \u001b[0mitem\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_iterator\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     47\u001b[0m             \u001b[0;32myield\u001b[0m \u001b[0mitem\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     48\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/openai/_streaming.py\u001b[0m in \u001b[0;36m__stream__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m     70\u001b[0m                         \u001b[0mmessage\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"An error occurred during streaming\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     71\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 72\u001b[0;31m                     raise APIError(\n\u001b[0m\u001b[1;32m     73\u001b[0m                         \u001b[0mmessage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     74\u001b[0m                         \u001b[0mrequest\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mAPIError\u001b[0m: The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently."
     ]
    }
   ],
   "source": [
    "import os\n",
    "from praisonai import PraisonAI\n",
    "from google.colab import userdata\n",
    "\n",
    "# Create a PraisonAI instance with the agent_yaml content\n",
    "praisonai = PraisonAI(agent_yaml=agent_yaml, tools=[GenerateImageTool, FileReadTool, MarkdownToPDFTool])\n",
    "\n",
    "# Add OPENAI_API_KEY Secrets to Google Colab on the Left Hand Side 🔑 or Enter Manually Below\n",
    "os.environ[\"OPENAI_API_KEY\"] = userdata.get('OPENAI_API_KEY') or \"ENTER OPENAI_API_KEY HERE\"\n",
    "os.environ[\"OPENAI_MODEL_NAME\"] = \"gpt-5-nano\"\n",
    "\n",
    "# Run PraisonAI\n",
    "result = praisonai.run()\n",
    "\n",
    "# Print the result\n",
    "print(result) # 2/10\n"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
